package operation;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2023-08-17
 * Time: 10:51
 */
public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入要归还图书的名字");
            String name=sc.nextLine();

            //遍历书架，去查找有无此书
            int currentSize=bookList.getUsedSized();
            for (int i = 0; i <currentSize; i++) {
                if(name.equals(bookList.getBooks(i).getName())){
                    //如果有，看它是否有被借出
                    if(bookList.getBooks(i).isBorrowed()==true){
                        System.out.println("归还成功");
                        bookList.getBooks(i).setBorrowed(false);
                        return;
                    }else{
                        System.out.println("该书未被借出");
                        return;
                    }
                }
            }
            System.out.println("没有此书");
        }
    }

